home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * Get the contents of a directory from TwinExpres from DOpus.
- *
- * (c) 1994 by K.P. van Beem (2:280/464.2, patrick.van.beem@aobh.xs4all.nl)
- *
- * Based on the DOpusLhaARexx package by Geoff Seeley (but you can better
- * use GuiArc in stead of DOpus and a script, to deal with archives)
-
- ---- modified by Ray Abram
- - Bug Fix... If a Device is requested to go into a dir on the remote
- that is not there, then the Twin REXX program
- will hang...
- ie:- a dir of DH0: on a CD32...
- - solution try a CD to the remote, if an error occurs then exit
-
- - File sorting, with dirs at the top and files at the bottom..
-
- - Caching
- - if a file is found with the same name as the requested
- dir to read in, then that file is used to get the info from
- - Use ReRead.rexx to delete the dir files if you need to reread
- dir listings
- - note the files stored by the caching system replace
- : (a device name) -> ;
- / (a dir seperator) -> \
- *** thus if a dir name contains these characters, then the caching
- logic will become confused and not work...
- - now sorts dirs from files as the dir info from Twin is read in
- *
- */
-
- DOpusPort = 'DOPUS.1'
- HandlerPort = 'TWIN.1'
-
- userdata = ' 0' /* default */
- fgpen = ' 1' /* palette 1 */
- dirpen = ' 3' /* for directories */
- bgpen = ' 0' /* palette 2 */
- selectable = ' 1' /* can select */
- unselectable = ' 0' /* can't select */
- show = ' 0' /* update win */
- before = ' -1' /* add to end */
-
- if ~show(l,"rexxsupport.library") then
- call addlib("rexxsupport.library",0,-30,0)
- if showlist('Ports', DOpusPort) = 0 then do
- say 'Directory Opus Arexx port not found. Aborting.'
- call CleanUp
- end
-
- address 'DOPUS.1'
- options results
-
- trace ?results
-
- /* Get some information from DOpus */
- parse arg FilePath
- if FilePath="" then do
- TopText "You have to specify a directory. !!"
- exit
- end
- Status 3
- CurrentWindow = Result
-
- /* check for spaces in filename */
- if words(FilePath) > 1 then do
- Request "Spaces in a Filename are not Allowed !!"
- exit
- end
-
- /* Caching addition
- check for the caching file,
- if not found then make the file
- if it is present then use the file
- */
-
- CacheFile = 'TwinDirs:' || ConvertFilename(FilePath)
-
- /* check for the dir already stored */
- if exists(CacheFile) then
- Cach=True
- else
- Cache=False
-
- if Cache=False then do
- if left(FilePath,1) = '~' then
- pt = "Remote has"
- else
- pt = "that there are"
-
- /*check that the remote directory exists ??? */
- TOPTEXT "Checking to see if" FilePath "Exists ... (Ensure" pt "no Requestors !!)"
- sd = EnterDir(FilePath)
- address command 'echo >PPipe: dir ' sd
- address command 'echo >PPipe: help'
- if open(PipeList, "QUEUE:Twin", 'R') then do
- /* skip the header and the 'help-flush' from the last call... */
- junk = ''
- test = ''
- do while ((test ~= "TWIN> D") & (test ~= "TWIN> E") & (test ~= "Error: ") & (test ~= "Deafult"))
- junk = readln(PipeList)
- test = left(junk , 7, '')
- end
- close(PipeList)
- if ((test = "TWIN> E") | (test = "Error: ")) then do
- parse var test left '~' right
- if right ~= '' then
- Request "Local " FilePath "NOT FOUND ????"
- else
- Request "Remote " FilePath "NOT FOUND ????"
-
- TopText 'Ready'
-
- Busy off
- exit
- end
- end
- else do
- TopText "Can't open pipe:"
- call CleanUp
- end
- end
-
-
- /* setup DOpus window and tell user what's happening */
- ClearWin CurrentWindow
- SetWinTitle FilePath
- Busy on
- TopText "Getting directory , Please Wait..."
-
- /* Address the list command and a help to 'flush' the queue buffer
- * never use a queue with a bigger buffer than the default buffer.
- * The queue-handler doesn't flush automatically!
- */
- if Cache=False then do
- address command 'echo >PPipe: dir' FilePath
- address command 'echo >PPipe: help'
- end
-
- /* parse the result from pipe: */
- TopText "Parsing File(s). Please Wait..."
- call ParseDir
- 'DisplayDir -1'
-
- /* if handler is running, attach a custom handler to the window */
- if show('p', HandlerPort) then
- 'AddCustHandler '||HandlerPort||' -1'
-
- Busy off
- call CleanUp
- exit
-
- /*---------------------------------------------------------------------------*/
-
- ParseDir:
-
- if open(PipeList, "QUEUE:Twin", 'R') then do
-
- if Cache=False then do
- /* skip the header and the 'help-flush' from the last call... */
- junk = ''
- do while left(junk, 10, '') ~= "Listing of"
- junk = readln(PipeList)
- end
- junk = readln(PipeList)
-
- /* read files and dirs and save them to separate temp files*/
- open(dirs, "T:twin.dirs" , 'W')
- open(files, "T:twin.files", 'W')
-
- line = readln(PipeList)
- lines = 0
- f_count = 0
- d_count = 0
- do while length(line) ~= 0
- if SubStr(line,26,9) = 'Directory' then do
- writeln(dirs, line)
- d_count = d_count + 1
- end
- else do
- writeln(files, line)
- f_count = f_count + 1
- end
-
- /* get the next line */
- lines = lines + 1
- line = readln(PipeList)
- end
- close(dirs )
- close(files)
-
- /* only sort Dirs and files if there is something to sort ... */
- if lines > 0 then do
-
- /*write data out to the cache file as it is read in...*/
- open(cache, CacheFile, 'W')
-
- /*sort the Dirs and store then into DOPus*/
- if d_count > 0 then do
- /* tell user what we are doing */
- TOPTEXT "Sorting Directories..."
-
- address command "sort t:twin.dirs t:twin.dirs2"
- /*read in the sorted data dirs then files... */
- open(dirs, "T:twin.dirs2" , 'R')
- line = readln(dirs)
- do while length(line) ~= 0
- writeln(cache , line) /* store to cache file*/
- File = Quote(line)
- Entry = File || userdata || dirpen || bgpen || selectable || show || before
- AddCustEntry Entry
- line = readln(dirs)
- end
- close(dirs)
- end
-
- /*sort the Files and store then into DOPus*/
- if f_count > 0 then do
- /* tell user what we are doing */
- TOPTEXT "Sorting Files..."
-
- address command "sort t:twin.files t:twin.files2"
- open(files, "T:twin.files2" , 'R')
- line = readln(files)
- do while length(line) ~= 0
- writeln(cache , line) /* store to cache file*/
- File = Quote(line)
- Entry = File || userdata || fgpen || bgpen || selectable || show || before
- AddCustEntry Entry
- line = readln(files)
- end
- close(files)
- end
-
- close(cache)
-
- /*and now delete all temp files */
- address command "delete t:twin.dirs"
- address command "delete t:twin.dirs2"
- address command "delete t:twin.files"
- address command "delete t:twin.files2"
- end /* if there are some files */
-
- close(PipeList)
- end
- else do
- /*read in the stored cache file...*/
- TOPTEXT "Loading Cached Information..."
- open(cache, CacheFile, 'R')
- line = readln(cache)
- do while length(line) ~= 0
- File = Quote(line)
- if SubStr(line,26,9) = 'Directory' then
- Entry = File || userdata || dirpen || bgpen || selectable || show || before
- else
- Entry = File || userdata || fgpen || bgpen || selectable || show || before
- AddCustEntry Entry
- line = readln(cache)
- end
- close(cache)
- end
-
- /* add invisible entry giving us the path for recognition of the twin dir*/
- File = Quote('*'||FilePath)
- Entry = File || userdata || bgpen || bgpen || unselectable || show || before
- AddCustEntry Entry
-
- end
- else do
- TopText "Can't open pipe:"
- call CleanUp
- end
-
- return
-
- /*---------------------------------------------------------------------------*/
-
- CleanUp:
-
- TopText "Ready"
- Busy off
- exit
-
- return
-
- /*---------------------------------------------------------------------------*/
-
- Quote: procedure /* add quotes to string */
-
- parse arg string
-
- return '"'||string||'"'
-
- /*---------------------------------------------------------------------------*/
-
- /* convert a file name from df0:ray/was/here -> df0=ray\was\here
- then to -> d0=ry\ws\he (cache filename)*/
- ConvertFilename: procedure
-
- parse arg Dev ':' Path
-
- if left(dev,1) = '~' then
- dev = '`' || right(dev,length(dev)-1)
-
- t2 = ''
- Convert = ''
- do until (t2 = '')
- parse var Path t1 '/' t2
- Path = t2
- if t2 ~= '' then
- end = '\'
- else
- end = ''
- Convert = Convert || left(t1,1) || right(t1,1) || end
- end
-
- if left(Convert,1) = ' ' then
- Convert = ''
-
- out = Dev || '=' || Convert
-
- return out
-
- /*--------------------------------------------------------------------------*/
-
- /* Cd into the sent Directory path
- - this is needed, as TWIN has a command parameter limit of 30 characters,
- and as we all know AmigaDos file & paths can easily go over this limit !!*/
-
- EnterDir: procedure
-
- parse arg Dev ':' Path
-
- /* get the 1st character to address the local or remote machine correctly */
- if left(Dev,1) = '~' then
- sbit = '~'
- else
- sbit = ''
-
- /* does the passed name have a DEVICE in it ? */
- if Dev ~= '' then
- address command 'echo >PPipe: cd' Dev || ':'
-
- do until (t2 = '')
- parse var Path t1 '/' t2
- path = t2
- if t1 ~= '' then
- address command 'echo >PPipe: cd' sbit || t1
- end
-
- return sbit
-
-